package com.example.mqdemo.Work.fairDispatch;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.support.AmqpHeaders;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.stereotype.Component;

import java.io.IOException;

/*
 *@description: 工作队列消息公平分发接收者
 *@author: hisen
 *@Time: 2023/11/21  10:13
 */
@Component("fairWorkConsumer2")
public class WorkConsumer2 {
    @RabbitListener(queues = "fair-dispatch_work", containerFactory = "fairWorkFactory")
    public void handleMessage(String message, Channel channel, @Header(AmqpHeaders.DELIVERY_TAG) Long deliveryTag) throws IOException {
        System.out.println("消费者2收到消息：" + message);
        channel.basicAck(deliveryTag, false);
    }
}